const baseUrl = 'https://api.mokyun.com/pesticide/'

const getData = myUrl => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + myUrl,
      method: 'GET',
      header: {
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + wx.getStorageSync('token'),
        'content-type': 'application/json',
        'APPID': 32
      },
      success: res => {
        if (res.statusCode == 200) {
          resolve(res.data)
        } else {
          reject('数据请求失败')
        }
      }
    })
  })
}


const qiniuToken = () => {
  return new Promise((resolve, reject) => {
    wx.request({
      url: "https://api.mokyun.com/qiniu/upload/token",
      method: "GET",
      header: {
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: res => {
        // console.log(res)
        resolve(res.data.token)
        // const uploadToken = res.data.token
        // that.setData({
          // uploadToken: uploadToken
        // })
      }
    })

  })
}

module.exports = {
  getData: getData,
  qiniuToken: qiniuToken
}